/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.text.DecimalFormat;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import thecliffproblem.Action;

/**
 *
 * @author Jaime
 */
public class SquareEvaluationPanel extends JPanel{
    
    private double[] evaluations;
    private JLabel[] labels;
    
    public SquareEvaluationPanel()
    {
        setLayout(new GridBagLayout());
        setBorder(BorderFactory.createLineBorder(Color.black));
        evaluations = new double[4];
        labels = new JLabel[4];
        
        labels[0] = new JLabel("0.0");
        labels[1] = new JLabel("0.0");
        labels[2] = new JLabel("0.0");
        labels[3] = new JLabel("0.0");
        
        GridBagConstraints gbc = new GridBagConstraints();
        //gbc.anchor = GridBagConstraints.PAGE_START;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.gridx = 1;
        gbc.gridy = 0;
        add(labels[0], gbc);
        
        
        //gbc.anchor = GridBagConstraints.PAGE_END;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.gridx = 1;
        gbc.gridy = 2;
        add(labels[1], gbc);
        
        //gbc.anchor = GridBagConstraints.LINE_END;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.gridx = 2;
        gbc.gridy = 1;
        add(labels[2], gbc);
        
        //gbc.anchor = GridBagConstraints.LINE_START;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.gridx = 0;
        gbc.gridy = 1;
        add(labels[3], gbc);
        
        resetGrid();
        
        
    }
    
    private void resetGrid()
    {
        int i = 0;
        DecimalFormat df = new DecimalFormat("0.00");
        for(JLabel label:labels)
        {
            label.setText(df.format(evaluations[i]));
            i++;
        }
    }
    
    public void setValue(Action action, double value)
    {
        evaluations[action.getID()] = value;
        resetGrid();
    }
    
  
    
}
